package com.jie.jie;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;

import com.ant.liao.GifView;
import com.bumptech.glide.Glide;
import com.jaydenxiao.common.commonutils.LogUtils;
import com.jie.jie.Fanshe.FansheActivity;
import com.jie.jie.PermissionDispatcher.PermissActivity;
import com.jie.jie.ShortCut.ShortCutActivity;
import com.jie.jie.andfix.AndFixActivity;
import com.jie.jie.camera.CameraActivity;
import com.jie.jie.cangtoushi.CangtoushiActivity;
import com.jie.jie.edit.EditActivity;
import com.jie.jie.mvp.ui.MVPActivity;
import com.jie.jie.mvp.ui.Meimei;
import com.jie.jie.percent.PercentActivity;
import com.jie.jie.rili.RiliActivity;
import com.jie.jie.svg.SVGActivity;
import com.jie.jie.view.ClockActivity;
import com.jie.jie.xiaohua.ui.XiaohuaActivity;
import com.jie.jie.yunxin.YLoginActivity;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {
    private RecyclerView rv;
    private MainRvAdapter rvAdapter;
    private List<String> strings;
    private List<String> datas;
    private GifView gif;
    private ImageView gif_iv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MainActivity.this, ShortCutActivity.class));
            }
        });

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
         initData();
        initrv();
    }

    private void initrv() {
        rv = (RecyclerView) findViewById(R.id.rv_main);
        rv.setLayoutManager(new LinearLayoutManager(this));
        rvAdapter = new MainRvAdapter(datas, this);
        rv.setAdapter(rvAdapter);
        gif = (GifView) findViewById(R.id.git);
        gif_iv = (ImageView) findViewById(R.id.git_iv);
        gif.setGifImage(R.drawable.aaa);
        Glide.with(this).load(R.drawable.aaa).asGif().into(gif_iv);

        rvAdapter.setItemonclick(new MainRvAdapter.Itemonclick() {
            @Override
            public void onclick(View view, int position) {
                switch (position) {
                    case 0:
                        startActivity(new Intent(MainActivity.this, FansheActivity.class));
                        break;
                    case 1:
                        startActivity(new Intent(MainActivity.this, MVPActivity.class));
                        break;
                    case 2:
                        startActivity(new Intent(MainActivity.this, XiaohuaActivity.class));
                        break;
                    case 3:
                        startActivity(new Intent(MainActivity.this, YLoginActivity.class));
                        break;
                    case 4:
                        startActivity(new Intent(MainActivity.this,PermissActivity.class));
                        break;
                    case 5:
                        startActivity(new Intent(MainActivity.this, CameraActivity.class));
                        break;
                    case 6:
                        startActivity(new Intent(MainActivity.this,AndFixActivity.class));
                        break;
                    case 7:
                        startActivity(new Intent(MainActivity.this, PercentActivity.class));
                        break;
                    case 8:
                        startActivity(new Intent(MainActivity.this, EditActivity.class));
                        break;
                    case 9:
                        startActivity(new Intent(MainActivity.this, RiliActivity.class));
                        break;
                    case 10:
                        startActivity(new Intent(MainActivity.this, CangtoushiActivity.class));
                        break;
                    case 11:
                        startActivity(new Intent(MainActivity.this, SVGActivity.class));
                        break;
                    case 12:
                        startActivity(new Intent(MainActivity.this, ClockActivity.class));
                        break;
                }
            }
        });
    }



    private void initData() {
        datas = new ArrayList<>();
        datas.add("反射");
        datas.add("mvp");
        datas.add("笑话");
        datas.add("网易云信");
        datas.add("PermissionDispatcher6.0权限");
        datas.add("相机");
        datas.add("AndFix");
        datas.add("百分比布局");
        datas.add("输入框");
        datas.add("日历");
        datas.add("藏头诗");
        datas.add("矢量图");
        datas.add("自定义时钟");



    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }


    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_camera) {
            onResume();
        } else if (id == R.id.nav_gallery) {
            onDestroy();
        } else if (id == R.id.nav_slideshow) {
            onStop();
        } else if (id == R.id.nav_manage) {
            onStart();
        } else if (id == R.id.nav_share) {
            onDestroy();
        } else if (id == R.id.nav_send) {
            startActivity(new Intent(MainActivity.this,Meimei.class));

        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

    @Override
    protected void onResume() {
        super.onResume();
        LogUtils.loge("onresume");

    }

    @Override
    protected void onStart() {
        super.onStart();
        LogUtils.loge("onstart");
    }

    @Override
    protected void onStop() {
        super.onStop();
        LogUtils.loge("onstop");

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        LogUtils.loge("ondestroy");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        LogUtils.loge("onrestart");
    }
}
